<template>
  <div class="api" style="margin-top: -5px">
    <!--搜索区域-->
    <el-row >
      <el-col :span="22">
        <span style="font-size: 14px;font-weight: 600">日志标题: &nbsp;</span>
        <el-input v-model="params.title" style="width: 150px" placeholder="请输入标题" clearable ></el-input>
        <span class="so">日志类型: &nbsp;</span>
        <el-select v-model="params.type"  clearable placeholder="请选择类型" style="width: 150px">
          <el-option
            v-for="item in logType"
            :key="item.dictKey"
            :label="item.dictValue"
            :value="item.dictKey">
          </el-option>
        </el-select>
        <span class="so">操作系统: &nbsp;</span>
          <el-select v-model="params.system" clearable placeholder="请选择操作系统" style="width: 150px">
            <el-option label="Windows" value="Windows"></el-option>
            <el-option label="Android" value="Android"></el-option>
            <el-option label="iPhone" value="iPhone"></el-option>
            <el-option label="Linux" value="Linux"></el-option>
         </el-select>
        <span class="so">操作设备: &nbsp;</span>
          <el-select v-model="params.mobileTerminal" clearable placeholder="请选择操作设备" style="width: 150px">
            <el-option label="PC" :value="false"></el-option>
            <el-option label="移动端" :value="true"></el-option>
          </el-select>
        <span class="so">访问结果: &nbsp;</span>
        <el-select v-model="params.success" clearable placeholder="请选择状态" style="width: 150px">
          <el-option label="成功" :value="true"></el-option>
          <el-option label="失败" :value="false"></el-option>
        </el-select>
      </el-col>
      <!--查询按钮-->
      <el-col :span="2">
        <el-button type="primary" plain style="width: 6vw" icon="Search" @click="getDataList()">查询</el-button>
      </el-col>
    </el-row>
    <!--表格区域-->
    <el-row style="margin-top: 15px">
      <el-col :span="24">
        <el-table
          :data="tableData" style="width: 100%"
          :header-cell-style="{'background-color':'#F2F6FC'}" empty-text="暂无数据">
          <el-table-column prop="title" label="日志标题" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="typeName" label="日志类型" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="system" label="操作系统" :show-overflow-tooltip="true">
            <template #default="scope">
              <el-tag>{{scope.row.system}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="mobileTerminal" label="操作设备" :show-overflow-tooltip="true">
            <template #default="scope">
              {{scope.row.mobileTerminal ? '移动端' : 'PC'}}
            </template>
          </el-table-column>
          <el-table-column prop="browser" label="浏览器" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="isp" label="运营商" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="address" label="地址" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="remoteIp" label="IP" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="time" label="耗时">
            <template #default="scope">
              {{scope.row.time}}ms
            </template>
          </el-table-column>
          <el-table-column prop="success" label="访问状态">
              <template #default="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :disabled="scope.row.success"
                  :content="scope.row.exceptionMsg"
                  placement="top-end">
                  <el-tag :type="scope.row.success ? '' : 'danger'">{{scope.row.success ? '成功' : '失败'}}</el-tag>
                </el-tooltip>
              </template>
          </el-table-column>
          <el-table-column prop="createBy" label="访问账号"></el-table-column>
          <el-table-column prop="createTime" label="访问时间" width="170"></el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-row style="margin-top: 15px" justify="end">
      <el-col >
        <el-pagination
          background
          style="float: right"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.current"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="params.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import DataAdd from '@/components/role/DataAdd'
import DataDetails from '@/components/role/DataDetails'
import DataUpdate from '@/components/role/DataUpdate'
import { ElMessage } from 'element-plus'
export default {
  name: 'Index',
  components:{
    DataUpdate,
    DataDetails,
    DataAdd
  },
  data () {
    return {
      params: {
        current: 1,
        size: 10,
        type: null,
        title: null,
        system: null
      },
      drawer:{
        title:'',
        enable:false,
        add:false,
        details:false,
        update:false,
        data:null
      },
      total:0,
      logType:[],
      tableData: [],
      selectId: []
    }
  },
  mounted () {
    this.getDataList()
    //数据字典
    this.getDateDict()
  },
  methods:{
    //获得页面数据
    getDataList(){
      this.$http.get('/api/logApi',{params:this.params}).then(res =>{
        this.tableData = res.data.data.records
        this.total = res.data.data.total
      })
    },
    // 分页-页面大小
    handleSizeChange(val) {
     this.params.size = val
      this.getDataList()
    },
    // 分页-当前页面
    handleCurrentChange(val) {
      this.params.current = val
      this.getDataList()
    },
    //获取字典
    getDateDict(){
      this.$http.get('/api/dict/list?codeList='+ 'log_type').then(res =>{
        this.logType = res.data.data.log_type
      })
    }
  }
}
</script>

<style scoped>
.so {
  margin-left: 10px;
  font-size: 14px;
  font-weight: 600;
}
.api {
  width: 100%;
}
</style>
